package edu.nf.bs.dao.impl;

import edu.nf.bs.dao.ExpressInfoMapper;
import edu.nf.bs.entity.ExpressInfo;
import edu.nf.bs.util.MyBatisUtils;
import org.apache.ibatis.session.SqlSession;

import java.util.List;

public class ExpressInfoMapperImpl implements ExpressInfoMapper {
    @Override
    public List<ExpressInfo> queryExpress(String expressId, Integer pageNum, Integer pageSize) {
        SqlSession sqlSession = MyBatisUtils.getSqlSession(true);
        ExpressInfoMapper mapper = sqlSession.getMapper(ExpressInfoMapper.class);
        List<ExpressInfo> expressInfos = mapper.queryExpress(expressId, pageNum, pageSize);
        sqlSession.close();
        return expressInfos;
    }

    @Override
    public int addExpress(ExpressInfo express) {
        SqlSession sqlSession = MyBatisUtils.getSqlSession(true);
        ExpressInfoMapper mapper = sqlSession.getMapper(ExpressInfoMapper.class);
        int r = mapper.addExpress(express);
        sqlSession.close();
        return r;
    }

    @Override
    public ExpressInfo queryExpressId(String expressId) {
        SqlSession sqlSession = MyBatisUtils.getSqlSession(true);
        ExpressInfoMapper mapper = sqlSession.getMapper(ExpressInfoMapper.class);
        ExpressInfo expressInfo = mapper.queryExpressId(expressId);
        sqlSession.close();
        return expressInfo;
    }

    @Override
    public Integer updateExpress(String expressId,float expressPrice) {
        SqlSession sqlSession = MyBatisUtils.getSqlSession(true);
        ExpressInfoMapper mapper = sqlSession.getMapper(ExpressInfoMapper.class);
        int r = mapper.updateExpress(expressId,expressPrice);
        sqlSession.close();
        return r;
    }
}
